/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package coms.interceptors;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

/**
 *
 * @author Atul
 */
public class LoggingInterceptor implements Interceptor{

    @Override
    public void destroy() {
        System.out.println("Destroy....");
    }

    @Override
    public void init() {
        System.out.println("Init...");
    }

    @Override
    public String intercept(ActionInvocation ai) throws Exception {
        String className = ai.getAction().getClass().getName();
        long startTime = System.currentTimeMillis();
        System.out.println("Before calling action: " + className);
        String result = ai.invoke();
        System.out.println("Logging Result is :" + result);
        long endTime = System.currentTimeMillis();
        System.out.println("After calling action: " + className + "Time Taken: " + (endTime - startTime) + " ms");
        return result;
    }
    
}
